package org.jivesoftware.spark.crowd;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.jivesoftware.spark.crowd.impl.Crowd;
import org.jivesoftware.spark.crowd.impl.Member;

public class EntityCreater {
	private static  Map<String,Class> imples = new HashMap<String,Class>();
	static {
		imples.put("Crowd", Crowd.class);
		imples.put("Member", Member.class);
	}
	public static Object create(String name,Class[] cls,Object[] params)throws Exception{
		if(cls.length != params.length)
			throw new Exception("param length error");
		Object obj = null;
		Class c = imples.get(name);	
		Constructor constructor = null;
		
			try {
				constructor = c.getConstructor(cls);
				obj =  constructor.newInstance(params);
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		return obj;
		
	}
}
